package com.zhenyi.jiahua.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jiahua.common.model.JhRole;
import com.jiahua.common.model.JhStaff;
import com.zhenyi.jiahua.index.JHController;

public class PermissionInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		try {
			JHController c = (JHController) controller;
			JhStaff staff = c.getStaff();
			c.setAttr("hasPermission", new HasPermissionFreeMarkerMethod(staff));
			c.setAttr("hasEditPermission", new HasEditPermissionFreeMarkerMethod(staff, c));
		} catch (Exception e) {
			controller.setAttr("hasPermission", false);
			controller.setAttr("hasEditPermission", JhRole.DISABLE_STYLE);
		}
		inv.invoke();
	}

}
